package com.example.thymeleaf.servlet;

import com.example.thymeleaf.service.UserService;
import com.example.thymeleaf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ddone
 * @date 2024/3/13-18:26
 */
@WebServlet("/deleteById")
public class DeleteUserServlet extends ViewBaseServlet{
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userid = req.getParameter("userid");
        int rows = userService.deleteById(userid);
        resp.sendRedirect(req.getContextPath()+"/findUsers");
    }
}
